package cn.lds.health.service.impl;

import cn.lds.health.constant.DsHealthConstant;
import cn.lds.health.dto.ResultDTO;
import cn.lds.health.entity.HealthExamItem;
import cn.lds.health.exception.SysException;
import cn.lds.health.mapper.HealthExamItemMapper;
import cn.lds.health.service.HealthExamItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

/**
 * @ClassName HealthExamItemServiceImpl
 * @Description TODO
 * @Author Christopher
 * @Date 2023/8/8 17:01
 * @Version 1.0
 **/

@Service
public class HealthExamItemServiceImpl implements HealthExamItemService {
	
	@Autowired
	private HealthExamItemMapper healthExamItemMapper;
	
	@Override
	public ResultDTO<List<HealthExamItem>> selectHealthExamItemAll() throws SysException {
		
		List<HealthExamItem> healthExamItems = healthExamItemMapper.selectExamItemAll();
		if (CollectionUtils.isEmpty(healthExamItems)){
			throw new SysException(DsHealthConstant.Query.QUERY_ERROR);
		}
		
		return ResultDTO.buildSuccess(healthExamItems);
	}
	
	@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
	@Override
	public ResultDTO addHealthExamItem(HealthExamItem examItem) throws SysException {
		
		int i = healthExamItemMapper.addHealthExamItem(examItem);
		
		if (i <= 0){
			throw new SysException(DsHealthConstant.Insert.ADD_ERROR);
		}
		return ResultDTO.buildSuccess();
	}
}